
$('document').ready(function() {	
	
		//select all the a tag with name equal to modal
		$('#uploadLink').click(function(e) {
			//Cancel the link behavior
			e.preventDefault();
			
			//Get the A tag
			var id = $(this).attr('href');
		
			
		
			//Get the window height and width
			var winH = $(window).height();
			var winW = $(window).width();
	              
			//Set the popup window to center
			$(id).css('top',  winH/2-$(id).height()/2);
			$(id).css('left', winW/2-$(id).width()/2);
		
			//transition effect
			$(id).fadeIn(1000); 
			return false;
		
		});
		
		//if close button is clicked
		$('.window .close').click(function (e) {
			//Cancel the link behavior
			e.preventDefault();
			$('.window').hide();
		});		
		
		//if close is clicked
		$('.close').click(function () {
			id = $(this).attr("id");
			id = id.substr('6',id.length);
			$('#'+id).fadeOut(500);
		});
		
		$('.image').click(function(){
			if($('.supp').css("display") == "block") 
				$('.supp').css("display","none");
		});
		
		$('.supp').click(function(){
			id = $(this).attr("id");
			$('#idImg').val(id);
			$('#formSuppImage').submit();

			retireImage("img_"+id);
		});
		
		$('.image').myBox({type:'image', effect:"rotate",setContent:true,clone:true});
});


retireImage = function(id){
	$('#'+id).fadeOut(500);
}

setDel = function(){
	if($('.supp').css("display") == "none") 
		$('.supp').css("display","block");
	else
		$('.supp').css("display","none");
}
function startUpload(){

    $('#result').css("display","none");
    $('#downloading').css("display","block");

}



function stopUpload(url){


	
	if (true){
	
	    $('#downloading').css("display","none");
	    $('#loading').css("display","block");
	    $('#result').html('<br><span id="lienUrl" class="spanImage"><b>Lien : </b>'+url+'</span><br><br><img id="imageUploader" src="" width="450px">');
	
	    var monImageJS = new Image;
	    monImageJS.onload = function(){
	        $('#loading').css("display","none");
	        $('#result').slideToggle(500,function(){
	        	window.setTimeout('$("#upload").fadeOut(500)',100);
	        	$('#nom').attr("value",monImageJS.src);
	        });
	    };
	    
	    monImageJS.src = url;
	    $('#imageUploader').attr("src",monImageJS.src);
	
	}else{
	
	    $('#downloading').css("display","none");
	    $('#loading').css("display","none");
	    $('#result').html('<span class="erreur">'+message+'</span>');
	    $('#result').slideToggle(500);
	
	    }
}

